package com.fwtai.controller.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.service.web.GoodsOrderService;
import com.fwtai.tool.ToolClient;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 微信支付订单控制层|路由层
 * @作者 李宇鹏
 * @版本 v1.0
 * @QQ号码 444141300
 * @创建日期 2023-04-11 13:44:15
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@RequestMapping("/goodsOrder")
public class GoodsOrderController{

  private final GoodsOrderService goodsOrderService;

  public GoodsOrderController(final GoodsOrderService goodsOrderService){
    this.goodsOrderService = goodsOrderService;
  }

  /**添加*/
  @PreAuthorize("hasAuthority('order_manage_btn_add')")
  @PostMapping("/add")
  public void add(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(goodsOrderService.add(request),response);
  }

  /**行内编辑*/
  @PreAuthorize("hasAuthority('order_manage_row_edit')")
  @PostMapping("/edit")
  public void edit(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(goodsOrderService.edit(request),response);
  }

  /**根据id查询对应的数据*/
  @PreAuthorize("hasAuthority('order_manage_row_queryById')")
  @GetMapping("/queryById")
  public void queryById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(goodsOrderService.queryById(id),response);
  }

  /**删除-单行*/
  @PreAuthorize("hasAuthority('order_manage_row_delById')")
  @PostMapping("/delById")
  public void delById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(goodsOrderService.delById(id),response);
  }

  /**批量删除*/
  @PreAuthorize("hasAuthority('order_manage_btn_delByKeys')")
  @PostMapping("/delByKeys")
  public void delByKeys(final String ids,final HttpServletResponse response){
    ToolClient.responseJson(goodsOrderService.delByKeys(ids),response);
  }

  /**获取数据*/
  @PreAuthorize("hasAuthority('order_manage_btn_listData')")
  @GetMapping("/listData")
  public void listData(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(goodsOrderService.listData(new PageFormData(request)),response);
  }

  /**获取优惠券列表*/
  @PreAuthorize("hasAuthority('order_manage_row_coupon_list')")
  @GetMapping("/listOrderCoupon")
  public void listOrderCoupon(final Long out_trade_no,final HttpServletResponse response){
    ToolClient.responseJson(goodsOrderService.listOrderCoupon(out_trade_no),response);
  }

  /**停止兑换|正常兑换优惠券*/
  @PreAuthorize("hasAuthority('order_manage_btn_coupon_edit')")
  @PostMapping("/updateAvailable")
  public void updateAvailable(final String kid,final String available,final String out_trade_no,final HttpServletResponse response){
    ToolClient.responseJson(goodsOrderService.updateAvailable(kid,available,out_trade_no),response);
  }
}